home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / as / as_front.c < prev    next >
C/C++ Source or Header  |  1990-08-09  |  3KB  |  114 lines

  1. /* 
  2.  * as.c --
  3.  *
  4.  *    Front end for assembler.
  5.  *
  6.  * Copyright 1989 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/cmds/as/RCS/as_front.c,v 1.2 90/08/06 21:07:58 rab Exp Locker: rab $";
  18. #endif /* not lint */
  19.  
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <stdlib.h>
  23. #include <sys/param.h>
  24. #include <assert.h>
  25.  
  26. #ifndef __STDC__
  27. #define const
  28. #endif
  29.  
  30. #ifndef EXIT_FAILURE
  31. #define EXIT_FAILURE    1
  32. #endif
  33.  
  34. #ifdef sun3
  35. static const char *hostMachine = "sun3";
  36. #else
  37. #ifdef sun4
  38. static const char *hostMachine = "sun4";
  39. #else
  40. #ifdef ds3100
  41. static const char *hostMachine = "ds3100";
  42. #else
  43. #ifdef symm
  44. static const char *hostMachine = "symm";
  45. #else
  46. NO DEFAULT TARGET MACHINE TYPE DEFINED
  47. #endif
  48. #endif
  49. #endif
  50. #endif
  51.  
  52. /*
  53.  *----------------------------------------------------------------------
  54.  *
  55.  * main --
  56.  *      Search through the command line arguments looking for an argument
  57.  *      of the form -mfoo, where `foo' is a machine type.  If found, delete
  58.  *      it from the list of arguments, and use it to determine which
  59.  *      backend to exec.  If there is no -m then default to the type
  60.  *      of the host machine.
  61.  *
  62.  * Results:
  63.  *    None.
  64.  *
  65.  * Side effects:
  66.  *    Execs machine assembler backend.
  67.  *
  68.  *----------------------------------------------------------------------
  69.  */
  70.  
  71. void
  72. main(argc, argv)
  73.     int argc;
  74.     char **argv;
  75. {
  76.     extern int errno;
  77.     int i;
  78.     int j;
  79.     const char *targetMachine;
  80.     char path[MAXPATHLEN];
  81.  
  82.     assert(argv[argc] == NULL);
  83.     targetMachine = hostMachine;
  84.     for (i = 1; i < argc; ++i) {
  85.     if (argv[i][0] == '-' && argv[i][1] == 'm') {
  86.         if (argv[i][2] == '\0') {
  87.         targetMachine = argv[i + 1];
  88.         if (targetMachine == NULL) {
  89.             fprintf(stderr, "No target machine specified\n");
  90.             exit(EXIT_FAILURE);
  91.         }
  92.         for (j = i; j < argc - 1; ++j) {
  93.             argv[j] = argv[j + 2];
  94.         }
  95.         argc -= 2;
  96.         assert(argv[argc] == NULL);
  97.         } else {
  98.         targetMachine = argv[i] + 2;
  99.         for (j = i; j < argc; ++j) {
  100.             argv[j] = argv[j + 1];
  101.         }
  102.         --argc;
  103.         assert(argv[argc] == NULL);
  104.         }
  105.         break;
  106.     }
  107.     }
  108.     sprintf(path, "/sprite/lib/gcc/%s.md/as.%s", hostMachine, targetMachine);
  109.     execv(path, argv);
  110.     fprintf(stderr, "Can't exec ``%s'': %s\n", path, strerror(errno));
  111.     exit(EXIT_FAILURE);
  112. }
  113.  
  114.